﻿using PitOfDespair.Dungeon;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Diagnostics;

namespace PitOfDespair.Tests
{
    
    
    /// <summary>
    ///This is a test class for FreeFormTest and is intended
    ///to contain all FreeFormTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FreeFormTest
    {
        const int XDimension=0;
        const int YDimension=1;


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


       
        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void FreeFormWestWallTest()
        {


            var generator = LevelWallHelper();
            var level=generator.Generate(0,0);
            var x = 0;
            foreach (var w in Enumerable.Range(0, level.GetUpperBound(YDimension)).Select(y => level[x, y].West))
                Assert.IsFalse(w == WallType.Open);
            
            
        }

      
        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void FreeFormEastWallTest()
        {


            var generator = LevelWallHelper();
            var level = generator.Generate(0,0);
            var x = level.GetUpperBound(XDimension);
            foreach (var w in Enumerable.Range(0, level.GetUpperBound(YDimension)).Select(y => level[x, y].East))
                Assert.IsFalse(w == WallType.Open);


        }

        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void FreeFormSouthWallTest()
        {


            var generator = LevelWallHelper();
            var level = generator.Generate(0,0);
            var y = level.GetUpperBound(YDimension);
            Debug.WriteLine("y is " + y);
            foreach (var w in Enumerable.Range(0, level.GetUpperBound(XDimension)).Select(x => level[x, y].South))
                Assert.IsFalse(w == WallType.Open);


        }

        [TestMethod()]
        [DeploymentItem("PitOfDespair.exe")]
        public void FreeFormNorthWallTest()
        {


            var generator = LevelWallHelper();
            var level = generator.Generate(0,0);
            var y = 0;
            foreach (var w in Enumerable.Range(0, level.GetUpperBound(XDimension)).Select(x => level[x, y].North))
                Assert.IsFalse(w == WallType.Open);


        }

        FreeForm_Accessor LevelWallHelper(int height=10, int width=10,int seed=1)
        {
            var rnd = new Random(seed);
            var target = new FreeForm_Accessor(height, width, rnd);
            return target;
        }
    }
}
